package gameplay;

public class Util {
  public static int getRandomNumber(int max) {
    return (int) Math.round(Math.random() * max);
    }
  
  public static int pointToGrid(int[][] grid, Point point) {
	  return grid[point.getY()][point.getX()];
  }
  
  public static Point coordinatesToPoint(String coordinates, Grid grid) {
    if (coordinates.length() < 2)
      return new Point(-1, -1);
	  int gridHeight = grid.getGrid()[0].length;
	  char letter = Character.toUpperCase(coordinates.charAt(0));
	  int y =  ((int) letter - 65);

	  int dizain = 0, unit = 0;
	  if (coordinates.length() > 2) {
	    dizain = (int) coordinates.charAt(1) - 48;
	    unit = (int) coordinates.charAt(2) - 48;	    
	  } else if (coordinates.length() == 2) { 
	    unit = (int) coordinates.charAt(1) - 48;
	  }
	  int x = dizain * 10 + unit;
	  Point point = new Point(x, y);
	  return point;
  }
}
